﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using pay.DAL;
using pay.Entity;
using pay.DAL.IDAL;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Text;

public partial class reg : System.Web.UI.Page
{
    protected string returnValue = "";//未插入数据

    protected void Page_Load(object sender, EventArgs e)
    {
        string userID;//硬件Md5
        int userNo;
        int loginType;
        bool loginExe;
        int sid;//广告发布位
        int trackId;//活动号
        int activityTag;
        long activityType;
        bool isCharging = false;
        string UserName;
        string VerifyCode;

        int errtag = 0;
        if (!string.IsNullOrEmpty(Request["userID"]))
        {
            userID = Request["userID"];
        }
        else 
        {
            errtag = 1;
            return;
        }

        if (!string.IsNullOrEmpty(Request["UserName"]))
        {
            UserName = Request["UserName"];
        }
        else
        {
            errtag = 1;
            return;
        }

        if (!string.IsNullOrEmpty(Request["VerifyCode"]))
        {
            VerifyCode = Request["VerifyCode"];
        }
        else
        {
            errtag = 1;
            return;
        }

        if (!int.TryParse(Request["userNo"], out userNo)) 
        {
            errtag = 2;
            return;
        }

        if (!int.TryParse(Request["loginType"], out loginType))
        {
            errtag = 2;
            return;
        }

        if (!bool.TryParse(Request["loginExe"], out loginExe))
        {
            errtag = 2;
            return;
        }

        if (!int.TryParse(Request["sid"], out sid))
        {
            errtag = 2;
            return;
        }

        if (!int.TryParse(Request["trackId"], out trackId))
        {
            errtag = 2;
            return;
        }

        if (!int.TryParse(Request["activityTag"], out activityTag))
        {
            errtag = 2;
            return;
        }

        if (!long.TryParse(Request["activityType"], out activityType))
        {
            errtag = 2;
            return;
        }

        //string userID;//硬件Md5
        //int userNo;
        //int loginType;
        //bool loginExe;
        //int sid;//广告发布位
        //int trackId;//活动号
        //int activityTag;
        //long activityType;
        //bool isCharging = false;

        if (errtag == 0) 
        {
            Tools tool = new Tools();
            tool.AddSqlParameter("pUserID", SqlDbType.VarChar, userID);
            tool.AddSqlParameter("pUserNo", SqlDbType.Int, userNo);
            tool.AddSqlParameter("pLoginType", SqlDbType.Int, loginType);
            tool.AddSqlParameter("pLoginExe", SqlDbType.Bit, loginExe);
            tool.AddSqlParameter("pSID", SqlDbType.Int, sid);
            tool.AddSqlParameter("pTrackID", SqlDbType.Int, trackId);
            tool.AddSqlParameter("pActivityTag", SqlDbType.Int, activityTag);
            tool.AddSqlParameter("pActivityType", SqlDbType.BigInt, activityType);
            tool.AddSqlParameter("pIsCharging", SqlDbType.Bit, isCharging);
            tool.AddSqlParameter("pUserName", SqlDbType.VarChar, UserName);
            tool.AddSqlParameter("pVerifyCode", SqlDbType.VarChar, VerifyCode);
            tool.AddSqlParameter("opMsg", SqlDbType.VarChar, 100, returnValue, ParameterDirection.Output);
            using (SqlConnection con = new SqlConnection(DBConn.Con_UserAgent))
            {
                con.Open();
                SqlDataReader reader = Emoney.DataAccess.SqlHelper.ExecuteReader(con, CommandType.StoredProcedure, "SP_Streak_WebActivate", tool.GetSqlParameters());                
            }
            returnValue = Tools.GetString(tool.GetSqlParameterByName("opMsg").Value);
        }

        Response.Write(alertInfo(returnValue));
        Response.End();
    }

    public string alertInfo(string info) 
    {
        StringBuilder result = new StringBuilder();
        result.AppendLine("<script type=\"text/javascript\">");
        result.AppendFormat("alert(\"{0}\");", info);
        result.AppendLine("window.close();");
        result.AppendLine("</script>");
        //Response.Write("");
        return result.ToString();
    }
}